﻿Public Class dlgFind
    Dim TCodeEditor As TextBoxPrj.CodeEditor
    Sub New(ByVal CodeEditor As TextBoxPrj.CodeEditor)
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        TCodeEditor = CodeEditor
    End Sub
    ''' <summary>
    ''' 关键字
    ''' </summary>
    ''' <remarks></remarks>
    Public strKeyWord As String
    ''' <summary>
    ''' 加载窗体
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub dlgFind_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblKeyWord.Text = GetTextInLanguageDoc("FindWhat", TextMode.Text)
        lblReplace.Text = GetTextInLanguageDoc("ReplaceWith", TextMode.Text)
        grpFindAndReplace.Text = GetTextInLanguageDoc("ReplaceWith", TextMode.Text)
        cmdNext.Text = GetTextInLanguageDoc("Next", TextMode.Text)
        cmdPrevious.Text = GetTextInLanguageDoc("Previous", TextMode.Text)
        cmdReplace.Text = GetTextInLanguageDoc("Replace", TextMode.Text)
        cmdReplaceALL.Text = GetTextInLanguageDoc("ReplaceAll", TextMode.Text)
        grpFindOptions.Text = GetTextInLanguageDoc("FindOptions", TextMode.Text)
        chkMatchWholeWord.Text = GetTextInLanguageDoc("MatchWholeWord", TextMode.Text)

        strKeyWord = TCodeEditor.MainDocument.GetSelectionText
        Me.txtKeyWord.Text = strKeyWord
    End Sub
    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        If Me.txtKeyWord.Text <> "" Then
            strKeyWord = Me.txtKeyWord.Text
            TCodeEditor.SetSearchWord(strKeyWord)
            TCodeEditor.FindNext()
            TCodeEditor.Focus()
        End If
    End Sub
    Private Sub cmdPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.Click
        If Me.txtKeyWord.Text <> "" Then
            strKeyWord = Me.txtKeyWord.Text
            TCodeEditor.SetSearchWord(strKeyWord)
            TCodeEditor.FindPrevious()
            TCodeEditor.Focus()
        End If
    End Sub
    Private Sub cmdReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReplace.Click
        If TCodeEditor.MainDocument.GetSelectionText <> String.Empty Then
            TCodeEditor.Replace(txtReplace.Text)
        Else
            cmdNext_Click(sender, e)
        End If
    End Sub
    Private Sub cmdReplaceALL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReplaceALL.Click
        TCodeEditor.ReplaceALL(txtKeyWord.Text, txtReplace.Text)
    End Sub
End Class